home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Games / Starter / JST / Developer / sources / src / loaders / Lotus / lotushd.asm < prev    next >
Encoding:
Assembly Source File  |  1999-12-03  |  7.6 KB  |  540 lines

  1. ; in V3 $76162.W could be set to $8000 if any protection problem occurs
  2.  
  3.     include    "jst.i"
  4.  
  5.  
  6.     HD_PARAMS    "lotus.d",958464,1
  7.  
  8. HDLOAD = 1
  9.  
  10. BUILD_MOVEW_REG:MACRO
  11. movw\1_\2:
  12.     move.w    \1,$\2
  13.     JSRGEN_FREEZE    FlushCachesHard
  14.     rts
  15.     ENDM
  16.  
  17. BUILD_MOVEB_REG:MACRO
  18. movb\1_\2:
  19.     move.b    \1,$\2
  20.     JSRGEN_FREEZE    FlushCachesHard
  21.     rts
  22.     ENDM
  23.  
  24. loader:
  25.     move.l    #$2000,D0
  26.     JSRABS    Alloc24BitMem
  27.     RELOC_MOVEL    D0,StackBase
  28.     beq    MemErr
  29.  
  30.     Mac_printf    "Lotus HD Loader & Fix (3 versions) V1.1"
  31.     Mac_printf    "Coded by JF Fabre © 1997-1998"
  32.     JSRABS    LoadDisks
  33.  
  34.     bsr    ReadBoot
  35.  
  36.     bsr    CheckVersion
  37.  
  38.     moveq.l    #0,D0
  39.     move.l    #CACRF_CopyBack,D1
  40.     JSRABS    Degrade
  41.  
  42. ;    WAIT_LMB
  43.  
  44.     GO_SUPERVISOR
  45.     SAVE_OSDATA    $80000
  46.     
  47.     bsr    InstallBoot
  48.  
  49.     JSRGEN    FreezeAll
  50.  
  51.     move.l    StackBase(pc),A7
  52.     lea    ($1C00,A7),A7
  53.  
  54.     JSRGEN    FlushCachesHard
  55.     move.l    version(pc),D0
  56.     cmp.l    #2,D0
  57.     beq    jmpv2$
  58.     cmp.l    #3,D0
  59.     beq    jmpv3$
  60.     JMP    $70024
  61. jmpv3$
  62.     jmp    $1010.W
  63. jmpv2$
  64.     JMP    $A1C.W
  65.  
  66. SetInt03:
  67.     STORE_REGS
  68.  
  69.     move.w    #$40,intreq+$DFF000    ; clear blitter interrupt
  70.     lea    NewInt03(pc),A0
  71.     move.l    A0,($6C).W
  72.  
  73.     move.l    NoIconify(pc),D0
  74.     bne    skip$            ; already set
  75.     move    SR,-(A7)
  76.     move    #$2700,SR        ; freeze!!
  77.     RELOC_STL    NoIconify
  78.     move    (A7)+,SR
  79. skip$
  80.  
  81.     RESTORE_REGS
  82.     rts
  83.  
  84. NewInt03:
  85.     btst    #6,dmaconr+$DFF000    ; blitter finished?
  86.     bne.b    retry$            ; no? just retry next time
  87.  
  88.     move.l    $D0.W,-(A7)        ; jump to next blit routine
  89.     rts
  90.  
  91. retry$
  92.     move.w    #$8040,intreq+$DFF000    ; sets blitter interrupt
  93.     rte
  94.  
  95. PatchProg_V3:
  96.     ; *** protection
  97.  
  98.     move.w    #$4E75,$72B92    ; seems to be a disk protection
  99.  
  100.     ; *** some in game checks for the protection
  101.  
  102.     move.w    #$4E75,$72C2A
  103.     move.l    #$4E714E71,$73D70
  104.     move.w    #$4E75,$74748
  105.  
  106.     PATCHGENJMP    $747A6,InGameExit    ; just in case...
  107.  
  108.     ; *** keyboard
  109.  
  110.     PATCHUSRJSR    $72C52,KbInt_V3    ; quit key
  111.     move.w    #$676A,$72C46        ; correct acknowledge
  112.  
  113.     ; *** self modifying code remove (prefetch problems)
  114.  
  115.     PATCHUSRJSR    $7888E,movwd5_788D6
  116.     PATCHUSRJSR    $78AFC,movwd0_78B06
  117.     PATCHUSRJSR    $78C22,movwd0_78C4A
  118.     PATCHUSRJSR    $788CE,movbd3_78915
  119.     PATCHUSRJSR    $78E94,movwd6_78ED8
  120.  
  121.     ; *** blitter stuff (tricky)
  122.  
  123.     bsr    PatchBlit
  124.     PATCHUSRJSR    $7879C,SetInt03        ; don't move this line above
  125.                         ; the PatchBlit call
  126.     
  127.     ; *** dbf delays
  128.  
  129.     bsr    PatchDbfs
  130.  
  131.     ; *** copper/iconify stuff
  132.  
  133.     bsr    PatchCopper
  134.  
  135.     JSRGEN    FlushCachesHard
  136.     nop
  137.     nop
  138.     rts
  139.     nop
  140.     nop
  141.     nop
  142.  
  143. PatchCopper:
  144.     STORE_REGS
  145.     lea    $72000,A0
  146.     lea    $78000,A1
  147.     move.l    #6,D0
  148.     move.l    #$F,D1
  149.     JSRGEN    PatchMoveCList_Idx
  150.  
  151.     PATCHUSRJMP    $DC.W,StoreCopperPtr
  152.     move.l    #$2D480080,D0
  153.     move.l    #$4EB800DC,D1
  154.     JSRGEN    HexReplaceLong
  155.     RESTORE_REGS
  156.     rts
  157.  
  158. StoreCopperPtr:
  159.     move.l    D0,-(A7)
  160.     move.l    A0,D0
  161.     JSRGEN_FREEZE    StoreCopperPointer
  162.     move.l    A0,($80,A6)            ; original game
  163.     move.l    (A7)+,D0
  164.     rts
  165.  
  166. PatchDbfs:
  167.     rts
  168.  
  169.     PATCHUSRJMP    $D6.W,DbfDelay
  170.     move.l    #$51C8FFFE,D0
  171.     move.l    #$4EB800D6,D1
  172.     lea    $72000,A0
  173.     lea    $79000,A1
  174.     JSRGEN    HexReplaceLong
  175.     rts
  176.  
  177. DbfDelay:
  178.     divu.w    #$28,D0
  179.     swap    D0
  180.     clr.w    D0
  181.     swap    D0
  182.     BEAM_DELAY    D0
  183.     rts
  184.  
  185. PatchBlit:
  186.     STORE_REGS
  187.  
  188.     ; search for the blitter interrupt clear/ $6C vector change
  189.     ; (just before the blit)
  190.  
  191.     move.l    #$006C3D7C,D0
  192.     move.l    #$0040009C,D1
  193.     lea    $78000,A0
  194.     lea    $7B000,A1
  195.  
  196. loop$
  197.     addq    #2,A0
  198.     move.l    (A0),D2
  199.     cmp.l    D0,D2
  200.     beq.b    found1$
  201.     cmp.l    A0,A1
  202.     bcs.b    exit$
  203.     bra.b    loop$
  204. found1$
  205.     move.l    4(A0),D2
  206.     cmp.l    D1,D2
  207.     beq.b    found2$
  208.     cmp.l    A0,A1
  209.     bcs.b    exit$
  210.     bra.b    loop$
  211.  
  212. found2$
  213.     move.w    #$D0,(A0)    ; replace $6C by $D0
  214. ;    move.w    #$4E71,(2,A0)
  215. ;    move.l    #$4E714E71,(4,A0)
  216.     bra.b    loop$
  217.  
  218. exit$
  219.     RESTORE_REGS
  220.     rts
  221.  
  222.  
  223. KbInt_V3:
  224.     move.b    D0,$7D7AE
  225.  
  226. KbInt_Common:
  227.     move.l    D1,-(A7)
  228.  
  229.     cmp.b    #$5F,D0        ; Help quits
  230.     bne    noquit$
  231.     JSRGEN_FREEZE    InGameExit
  232. noquit$
  233.     move.l    NoIconify(pc),D1
  234.     bne    noicon$        ; no iconify during races
  235.  
  236.     cmp.b    #$42,D0        ; TAB iconifies
  237.     bne    noicon$
  238.     JSRGEN_FREEZE    InGameIconify
  239. noicon$
  240.  
  241.     move.l    (A7)+,D1
  242.     rts
  243.  
  244. InstallBoot:
  245.     move.l    version(pc),D0
  246.     cmp.l    #2,D0
  247.     beq    InstallBoot_V2
  248.     cmp.l    #3,D0
  249.     beq    InstallBoot_V3
  250.  
  251. InstallBoot_V1:
  252.  
  253.     ; ** install program in $400
  254.  
  255.     lea    boot(pc),A0
  256.     lea    $400(A0),A0
  257.     lea    $400.W,A1
  258.  
  259.     move.w    #$3FF,D0
  260. copy$
  261.     move.l    (A0)+,(A1)+
  262.     dbf    D0,copy$
  263.  
  264.     ; ** install program in $70000
  265.  
  266.     lea    boot(pc),A0
  267.     lea    $66(A0),A0
  268.     lea    $70000,A1
  269.  
  270.     move.w    #$3FF,D0
  271. copy2$
  272.     move.l    (A0)+,(A1)+    ; strange to copy $1000 bytes as
  273.     dbf    D0,copy2$    ; only $400 bytes are read.
  274.  
  275.     PATCHUSRJMP    $5B0.W,ReadDisk_V1
  276.     move.w    #$4E75,$4FA.W
  277.     move.w    #$4E75,$4CC.W
  278.     move.w    #$4E75,$536.W
  279.  
  280.     PATCHUSRJMP    $700EA,PatchProg_V1
  281.     rts
  282.  
  283.  
  284. InstallBoot_V2:
  285.     lea    boot(pc),A0
  286.     lea    $400(A0),A0
  287.     lea    $A00.W,A1    ; install in $A00
  288.  
  289.     move.w    #$3FF,D0
  290. copy$
  291.     move.l    (A0)+,(A1)+
  292.     dbf    D0,copy$
  293.  
  294.     move.w    #$4E75,$E0E.W
  295.     move.w    #$4E75,$AD6.W
  296.     move.w    #$4E75,$AFE.W
  297.     move.w    #$4E75,$B2E.W
  298.     move.w    #$4E75,$16BC.W
  299.  
  300.     PATCHUSRJMP    $BDE.W,ReadDisk_V2
  301.     
  302.     rts
  303.  
  304. InstallBoot_V3:
  305.     LEA    boot(PC),A0
  306.     lea    ($4A,A0),A0
  307.  
  308.     LEA    $40000,A1
  309.     LEA    $1000.W,A3
  310.     MOVEA.L    A1,A2
  311.     MOVE    #$00FF,D7
  312.     MOVE    D7,D6
  313.  
  314. LAB_0002:
  315.     MOVE.L    (A0)+,(A1)+
  316.     DBF    D7,LAB_0002    ; install in $40000
  317.  
  318.     PATCHUSRJMP    $40110,ReadDisk_V3
  319.     move.w    #$4E75,$400A4
  320.     move.w    #$4E75,$4007C
  321.     move.w    #$4E75,$400D0
  322.     move.w    #$4E75,$4017C
  323. ;    move.w    #$600A,$40038
  324.  
  325. LAB_0003:
  326.     MOVE.L    (A2)+,(A3)+
  327.     DBF    D6,LAB_0003    ; install in $1000
  328.  
  329.  
  330.     rts
  331.  
  332. ReadDisk_V3:
  333.     movem.l    D1-D6/A0-A6,-(sp)
  334.  
  335.     bsr    NibRead
  336.     
  337.     movem.l    (sp)+,D1-D6/A0-A6
  338.     moveq    #0,D0
  339.  
  340.     cmp.l    #$72000,(sp)
  341.     beq    PatchProg_V3
  342.     rts
  343.  
  344. ReadDisk_V1:
  345.     movem.l    D1-D6/A0-A6,-(sp)
  346.  
  347.     bsr    NibRead
  348.     
  349.     movem.l    (sp)+,D1-D6/A0-A6
  350.     moveq    #0,D0
  351.  
  352.     rts
  353.  
  354. ReadDisk_V2:
  355.     movem.l    D1-D6/A0-A6,-(sp)
  356.  
  357.     bsr    NibRead
  358.     
  359.     movem.l    (sp)+,D1-D6/A0-A6
  360.     moveq    #0,D0
  361.  
  362.     cmp.l    #$72300,(A7)
  363.     beq    PatchProg_V2
  364.  
  365.     rts
  366.  
  367. PatchProg_V2:
  368.     STORE_REGS
  369.  
  370.     bsr    PatchProgCommon
  371.  
  372.     ; *** reset sprites, flush caches
  373.  
  374.     JSRGEN    FlushCachesHard
  375.  
  376.     RESTORE_REGS
  377.  
  378.     rts    ; jmp $72300
  379.  
  380.  
  381. PatchProg_V1:
  382.     ; *** finish code
  383.  
  384.     lea    $72308,A0
  385.     JSR    $408.W
  386.  
  387.     STORE_REGS
  388.  
  389.     bsr    PatchProgCommon
  390.  
  391.     ; *** reset sprites, flush caches
  392.  
  393.     JSRGEN    FlushCachesHard
  394.  
  395.     RESTORE_REGS
  396.  
  397.     JMP    $72308
  398.  
  399.  
  400. PatchProgCommon:
  401.     ; *** kb int
  402.  
  403.     PATCHUSRJSR    $72EFE,KbInt_V12
  404. ;;;;;    move.w    #$4E71,$72F62        ; allows kb reset
  405.  
  406.     ; *** prefetch remove
  407.  
  408.     PATCHUSRJSR    $78802,movwd5_7884A
  409.     PATCHUSRJSR    $78A70,movwd0_78A7A
  410.     PATCHUSRJSR    $78B96,movwd0_78BBE
  411.     PATCHUSRJSR    $78842,movbd3_78889
  412.     PATCHUSRJSR    $78ED8,movwd6_78E4C
  413.  
  414.     ; *** blitter stuff (tricky)
  415.  
  416.     bsr    PatchBlit
  417.     PATCHUSRJSR    $78710,SetInt03        ; don't move this line above
  418.  
  419.     ; *** dbf delays
  420.  
  421.     bsr    PatchDbfs
  422.  
  423.     ; *** copper/iconify stuff
  424.  
  425.     bsr    PatchCopper
  426.  
  427.     RTS
  428.  
  429.     ; v1 and v2
  430.  
  431.     BUILD_MOVEW_REG    d5,7884A
  432.     BUILD_MOVEW_REG    d0,78A7A
  433.     BUILD_MOVEW_REG    d0,78BBE
  434.     BUILD_MOVEW_REG    d6,78E4C
  435.     BUILD_MOVEB_REG    d3,78889
  436.  
  437.     ; v3 (old version from Harry)
  438.  
  439.     BUILD_MOVEW_REG    d5,788D6
  440.     BUILD_MOVEW_REG    d0,78B06
  441.     BUILD_MOVEW_REG    d0,78C4A
  442.     BUILD_MOVEW_REG    d6,78ED8
  443.     BUILD_MOVEB_REG    d3,78915
  444.  
  445. ; Routine patchant la lecture
  446.  
  447. ; D1: Longueur en octets
  448. ; D0: Offset en octets (-$3000)
  449. ; A0: Buffer
  450.  
  451. NibRead:
  452.     RELOC_CLRL    NoIconify
  453.  
  454. skip$
  455.     sub.l    #$3000,D0        ; Substract the 2 track offset
  456.  
  457.     move.l    D1,D7            ; length read, returned in D7
  458.     beq    ReadNothing
  459.  
  460.     ; Calcul de l'offset fichier
  461.  
  462.     move.l    D0,D2
  463.     moveq.l    #0,D0
  464.     JSRGEN    ReadDiskPart
  465.  
  466. ReadNothing:
  467.     rts
  468.  
  469. KbInt_V12:
  470.     move.b    D0,$7D868
  471.     bra    KbInt_Common
  472.  
  473. ReadBoot:
  474.     lea    bootname(pc),A0
  475.     lea    boot(pc),A1
  476.     moveq    #0,D0
  477.     move.l    #$1200,D1
  478.     JSRGEN    ReadFileHD
  479.     tst.l    D0
  480.     bne    BootErr
  481.     RTS
  482.  
  483.  
  484.  
  485. CheckVersion:
  486.     moveq    #0,d0
  487.     moveq.l    #4,D2
  488.     moveq.l    #4,D1
  489.     lea    verbuff(pc),A0
  490.     JSRGEN    ReadDiskPart
  491.     move.l    (A0),D0
  492.  
  493.     cmp.l    #$B322C,D0
  494.     bne    notv1$        ; the patched ver
  495.     RELOC_MOVEL    #1,version
  496.     rts
  497. notv1$
  498.     cmp.l    #$B3268,D0
  499.     bne    notv2$        ; the version from CD32 rip
  500.     RELOC_MOVEL    #2,version
  501.     rts
  502. notv2$
  503.     cmp.l    #$B3774,D0
  504.     bne    notv3$        ; the version from Harry
  505.     RELOC_MOVEL    #3,version
  506.     rts
  507.  
  508. notv3$
  509.     Mac_printf    "** Unknown version. Contact author."
  510.     JMPABS    CloseAll
  511.  
  512. BootErr:
  513.     Mac_printf    "** File ''lotus.b1'' not found!"
  514.     JMPABS    CloseAll
  515.  
  516. MemErr:
  517.     Mac_printf    "** Low memory. Can't run!"
  518.     JMPABS    CloseAll
  519.  
  520. verbuff:
  521.     dc.l    0
  522.  
  523. version:    
  524.     dc.l    0
  525.  
  526. StackBase:
  527.     dc.l    0
  528.  
  529. NoIconify
  530.     dc.l    0
  531.  
  532. boot:
  533.     blk.b    $1200,0
  534.     even
  535.  
  536. bootname:
  537.     dc.b    "lotus.b1",0
  538.     cnop    0,4
  539.  
  540.